package com.yunhai.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.tms.StoreGroup;
import com.yunhai.model.vo.tms.StoreGroupAdd;
import com.yunhai.model.vo.tms.StoreGroupQuery;
import com.yunhai.model.vo.tms.StoreGroupUpdate;
import com.yunhai.store.service.StoreGroupService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/storeGroup")
public class StoreGroupController {

    @Resource
    private StoreGroupService storeGroupService;


    /**
     * 获取 StoreGroup 分页列表
     */
    @GetMapping("/pagination")
    public Ret getStoreGroupPagination(PaginationVo paginationVo, StoreGroupQuery storeGroupQuery ) throws Exception {
        IPage page = storeGroupService.getStoreGroupPagination(paginationVo, storeGroupQuery);
        return Ret.toPage(page);
    }


    /**
     * 获取 StoreGroup 所有数据
     */
    @GetMapping("/all")
    public Ret getStoreGroupAllList( StoreGroupQuery storeGroupQuery ) throws Exception {
        List<StoreGroup> list = storeGroupService.getStoreGroupAllList( storeGroupQuery );
        return Ret.ok(list);
    }

    /**
     * 获取 StoreGroup 详情
    */
   @GetMapping("/{id}")
   public Ret getStoreGroupDetail(@PathVariable Long id) throws Exception {

       StoreGroup storeGroup = storeGroupService.getStoreGroupDetail(id);
       return Ret.ok(storeGroup);
   }


    /**
     * 新增 StoreGroup
     * */
    @PostMapping("")
    public Ret addStoreGroup(@RequestBody StoreGroupAdd storeGroupAdd) throws Exception {

        storeGroupService.addStoreGroup(storeGroupAdd);
        return Ret.ok();
    }


    /**
     * 更新 StoreGroup
     * */
    @PutMapping("")
    public Ret updateStoreGroup(@RequestBody StoreGroupUpdate storeGroupUpdate) throws Exception {

        storeGroupService.updateStoreGroup(storeGroupUpdate);
        return Ret.ok();
    }


    /**
     * 删除 StoreGroup
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveStoreGroup( @RequestBody List<Long> ids ) throws Exception {

        storeGroupService.batchRemoveStoreGroup(ids);
        return Ret.ok();
    }
}

  